<?php
$userid = islogin();
$sn  = empty($_POST['sn']) ? 0 : trim($_POST['sn']);
if(empty($sn)){
	exit('参数丢失');
}
$oOrder = new Order();
$__orderinfo = $oOrder->get_order_by_sn($sn, '*');
if(empty($__orderinfo)){
	sysinfo('订单不存在', "./index.php?frm=user&mdl=order&do=list", 5000);
}
switch($__orderinfo['state']){
	case '-2':
		sysinfo('订单已关闭', "./index.php?frm=user&mdl=order&do=show&sn={$sn}", 5000);
		break;
	case '-1':
		sysinfo('订单无效', "./index.php?frm=user&mdl=order&do=show&sn={$sn}", 5000);
		break;
	case '1':
	case '2':
		if($__orderinfo['payment_state'] == 2){
			sysinfo('您已经付过款了', "./indexp.hp?frm=user&mdl=order&do=show&sn={$sn}", 5000);
		}
		break;
}
// 取订单商品
$__orderinfo['goodslist'] = $oOrder->get_order_goods_all($sn, $detail = true);
$goods_names = array();
foreach($__orderinfo['goodslist'] as $goods){
	$goods_names[] = $goods['goodsinfo']['name'];
}
$__orderinfo['goods_names'] = $goods_names;
VS::set('orderinfo', $__orderinfo);

if(empty($__orderinfo['payment'])){
	exit('Payment lost!');
}else{
	// 支付方式配置信息
	$__payment_files = cache_read('payment_files.php');
	$__payment_file = $__payment_files['list'][$__orderinfo['payment']];
	VS::set('payment_file', $__payment_file);

	// 支付方式
	$__payments = cache_read('payments.php');
	$__payment_info = $__payments[$__orderinfo['payment']];
	VS::set('payment_info', $__payment_info);
	

	// 配送方式
	$__deliverys = cache_read('deliverys.php');
	$__delivery_info = $__deliverys[$__orderinfo['delivery']];

	// 收到地址
	$__address_info = $oOrder->get_order_address($__orderinfo['sn']);

	if(file_exists(APP_PTH.$__payment_file['path'].'/input.php')){
		include_once APP_PTH.$__payment_file['path'].'/input.php';
	}else{
		//exit('plugin payment not found');
	}
}
?>